<template>
    <div>
        <table>
            <tbody>
                <tr>
                    <td>用户名</td>
                    <td>
                        <input type="text" v-model="admin.Name">
                    </td>
                </tr>

                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="admin.Pwd">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive} from 'vue'
import axios from 'axios';
import {useRouter} from 'vue-router'
const router=useRouter();

let admin=reactive({
  "Id":0,
  "Name": "",
  "Pwd": ""
})

const ok=()=>{
    //验证
    if(admin.Name==""){
        alert('用户名不能为空');
        return;
    }
    if(admin.Pwd==""){
        alert('密码不能为空');
        return;
    }
    //发送网络请求
    axios({
        method:'get',
        url:'/api/Admin/Login',
        params:admin
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('用户名不存在');
            return;
        }
        if(res.data==-2){
            alert('密码错误');
            return;
        }
 
            alert('登录成功');
            router.push('/memberList')
      
       
    })
    .catch(err=>{
        console.log(err);
    })

}

</script>

<style scoped>

</style>